﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel;

namespace OOLib
{
   /// <summary>
   /// Represents a component which is created from an URL and arguments.
   /// </summary>
   /// <remarks>
   /// It is a representation of a resource in the sense that it was created/loaded from the resource. 
   /// The arguments are passed to the loader to modify its behavior. An example for such an argument is "AsTemplate", 
   /// which loads the resource as a template for a new document. (see ::com::sun::star::document::MediaDescriptor for further details) 
   /// Models can be controlled by controller components, which are usually views of the model. (see Controller for further details) 
   /// If there is at least one controller, there is by definition a current controller. And if that controller supports the 
   /// interface ::com::sun::star::view::XSelectionSupplier, it has a current selection too. 
   /// </remarks>
   public interface IModel
   {
      /// <summary>
      /// Informs a model about its resource description.
      /// </summary>
      /// <param name="url">Specifies the ressource.</param>
      /// <param name="arguments">Are optional arguments for that ressource (see ::com::sun::star::document::MediaDescriptor)</param>
      /// <returns>true for success, false otherwise</returns>
      bool AttachResource(string url, object[] arguments);

      /// <summary>
      /// Gets information about the location of this model.
      /// </summary>
      string Url { get; }

      /// <summary>
      /// Gets read acces on currently representation of the ::com::sun::star::document::MediaDescriptor of this model which describes the model and his state
      /// </summary>
      object[] Args { get; }

      /// <summary>
      /// Is called whenever a new controller is created for this model. 
      /// </summary>
      /// <param name="controller">A new controller for this model</param>
      /// <remarks>
      /// The ::com::sun::star::lang::XComponent interface of the controller must be used to recognize when it is deleted. 
      /// </remarks>
      void ConnectController(Controller controller);

      /// <summary>
      /// Is called whenever an existing controller should be deregistered at this model. 
      /// </summary>
      /// <param name="controller">The existing controller which should be deregistered </param>
      /// <remarks>
      /// The ::com::sun::star::lang::XComponent interface of the controller must be used to recognize when it is deleted. 
      /// </remarks>
      void DisconnectController(Controller controller);

      /// <summary>
      /// Suspends some notifications to the controllers which are used for display updates. 
      /// </summary>
      /// <remarks>
      /// The calls to XModel::lockControllers() and XModel::unlockControllers() may be nested and even overlapping, 
      /// but they must be in pairs. While there is at least one lock remaining, some notifications for display updates are not broadcasted. 
      /// </remarks>
      void LockControllers();

      /// <summary>
      /// Resumes the notifications which were suspended by XModel::lockControllers(). 
      /// </summary>
      /// <remarks>
      /// The calls to XModel::lockControllers() and XModel::unlockControllers() may be nested and even overlapping, 
      /// but they must be in pairs. While there is at least one lock remaining, some notifications for display updates are not broadcasted. 
      /// </remarks>
      void UnlockControllers();

      /// <summary>
      /// Gets if there is at least one lock remaining. 
      /// </summary>
      /// <remarks>
      /// While there is at least one lock remaining, some notifications for display updates are not broadcasted to the controllers. 
      /// </remarks>
      bool HasControllerLocked { get; }

      /// <summary>
      /// Gets access to the controller which currently controls this model 
      /// </summary>
      /// <remarks>
      /// If the controller which is active is a controller of this model, it will be returned. 
      /// If not, the controller which was the last active of this model is returned. 
      /// If no controller of this model ever was active, the controller first registered is returned. 
      /// If no controller is registered for this model, NULL is returned. 
      /// </remarks>
      Controller CurrentController { get; set; }

      /// <summary>
      /// Provides read access on current selection on controller .
      /// </summary>
      /// <remarks>
      /// Returns the current selection in the current controller. If there is no current controller, it returns NULL
      /// </remarks>
      ComObjectWrapper CurrentSelection { get; }
   }
}
